<!DOCTYPE html>
<html class="writer-html5" lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>selenium_driverless.webdriver &mdash; Selenium-Driverless 1.9.4 documentation</title>
      <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=80d5e7a1" />
      <link rel="stylesheet" type="text/css" href="../../_static/css/theme.css?v=19f00094" />

  
  <!--[if lt IE 9]>
    <script src="../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="../../_static/jquery.js?v=5d32c60e"></script>
        <script src="../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
        <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js?v=1ac0efc4"></script>
        <script src="../../_static/doctools.js?v=888ff710"></script>
        <script src="../../_static/sphinx_highlight.js?v=4825356b"></script>
    <script src="../../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" /> 
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../../index.html" class="icon icon-home">
            Selenium-Driverless
          </a>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
              <ul>
<li class="toctree-l1"><a class="reference internal" href="../../api/By.html">By Element Locator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Chrome.html">webdriver.Chrome</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/ChromeOptions.html">ChromeOptions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Context.html">Context</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Input.html">Input</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/RequestInterception.html">Request-Interception</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/Target.html">Target</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../api/WebELement.html">WebElement</a></li>
</ul>

        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../index.html">Selenium-Driverless</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="../index.html">Module code</a></li>
      <li class="breadcrumb-item active">selenium_driverless.webdriver</li>
      <li class="wy-breadcrumbs-aside">
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <h1>Source code for selenium_driverless.webdriver</h1><div class="highlight"><pre>
<span></span><span class="c1"># Licensed to the Software Freedom Conservancy (SFC) under one</span>
<span class="c1"># or more contributor license agreements.  See the NOTICE file</span>
<span class="c1"># distributed with this work for additional information</span>
<span class="c1"># regarding copyright ownership.  The SFC licenses this file</span>
<span class="c1"># to you under the Apache License, Version 2.0 (the</span>
<span class="c1"># &quot;License&quot;); you may not use this file except in compliance</span>
<span class="c1"># with the License.  You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1">#   http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1"># Unless required by applicable law or agreed to in writing,</span>
<span class="c1"># software distributed under the License is distributed on an</span>
<span class="c1"># &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY</span>
<span class="c1"># KIND, either express or implied.  See the License for the</span>
<span class="c1"># specific language governing permissions and limitations</span>
<span class="c1"># under the License.</span>

<span class="c1"># modified by kaliiiiiiiiii | Aurin Aegerter</span>
<span class="c1"># all modifications are licensed under the license provided at LICENSE.md</span>

<span class="sd">&quot;&quot;&quot;The WebDriver implementation.&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">shutil</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">tempfile</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">typing</span>
<span class="kn">import</span> <span class="nn">uuid</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">import</span> <span class="nn">signal</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">List</span>

<span class="c1"># io</span>
<span class="kn">import</span> <span class="nn">asyncio</span>

<span class="kn">import</span> <span class="nn">cdp_socket.exceptions</span>
<span class="kn">import</span> <span class="nn">websockets</span>

<span class="c1"># interactions</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.input.pointer</span> <span class="kn">import</span> <span class="n">Pointer</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types.webelement</span> <span class="kn">import</span> <span class="n">WebElement</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.scripts.switch_to</span> <span class="kn">import</span> <span class="n">SwitchTo</span>

<span class="c1"># contexts</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.sync.context</span> <span class="kn">import</span> <span class="n">Context</span> <span class="k">as</span> <span class="n">SyncContext</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types.context</span> <span class="kn">import</span> <span class="n">Context</span>

<span class="c1"># Targets</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.scripts.driver_utils</span> <span class="kn">import</span> <span class="n">get_target</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types.target</span> <span class="kn">import</span> <span class="n">Target</span><span class="p">,</span> <span class="n">TargetInfo</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types.base_target</span> <span class="kn">import</span> <span class="n">BaseTarget</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.sync.base_target</span> <span class="kn">import</span> <span class="n">BaseTarget</span> <span class="k">as</span> <span class="n">SyncBaseTarget</span>

<span class="c1"># others</span>
<span class="kn">from</span> <span class="nn">cdp_socket.utils.conn</span> <span class="kn">import</span> <span class="n">get_json</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types.options</span> <span class="kn">import</span> <span class="n">Options</span> <span class="k">as</span> <span class="n">ChromeOptions</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">sel_driverless_path</span>
<span class="kn">from</span> <span class="nn">selenium_driverless.types</span> <span class="kn">import</span> <span class="n">JSEvalException</span>
<span class="kn">from</span> <span class="nn">selenium_driverless</span> <span class="kn">import</span> <span class="n">EXC_HANDLER</span>


<div class="viewcode-block" id="Chrome"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome">[docs]</a><span class="k">class</span> <span class="nc">Chrome</span><span class="p">:</span>
<span class="w">    </span><span class="sd">&quot;&quot;&quot;Control the chromium based browsers without any driver.&quot;&quot;&quot;</span>
    <span class="n">port</span><span class="p">:</span> <span class="nb">int</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
            <span class="bp">self</span><span class="p">,</span>
            <span class="n">options</span><span class="p">:</span> <span class="n">ChromeOptions</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
            <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">30</span><span class="p">,</span>
            <span class="n">debug</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
            <span class="n">max_ws_size</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">**</span> <span class="mi">27</span>
    <span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="c1"># noinspection GrazieInspection</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Creates a new instance of the chrome target. Starts the service and</span>
<span class="sd">                then creates new instance of chrome target.</span>

<span class="sd">                .. code-block:: python</span>

<span class="sd">                    options = webdriver.ChromeOptions.rst()</span>
<span class="sd">                    async with webdriver.Chrome(options=options) as driver:</span>
<span class="sd">                        await driver.get(&#39;https://abrahamjuliot.github.io/creepjs/&#39;, wait_load=True)</span>
<span class="sd">                        print(await driver.title)</span>

<span class="sd">                :param options: this takes an instance of ChromeOptions.rst</span>
<span class="sd">                :param timeout: timeout in seconds to start chrome</span>
<span class="sd">                :param debug: redirect errors from the chromium process output (stderr) to console</span>
<span class="sd">                :param max_ws_size: maximum size for websocket messages in bytes. 2^27 ~= 130 MB by default</span>
<span class="sd">                &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_prefs</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_auth_interception_enabled</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_mv3_extension</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_extensions_incognito_allowed</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_base_context</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_stderr</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_stderr_file</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_process</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_current_target</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_host</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span> <span class="o">=</span> <span class="n">timeout</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">:</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">AbstractEventLoop</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">browser_pid</span><span class="p">:</span> <span class="nb">int</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_base_target</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_debug</span> <span class="o">=</span> <span class="n">debug</span>
        <span class="c1"># noinspection PyTypeChecker</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_current_context</span><span class="p">:</span> <span class="n">Context</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Context</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_temp_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">TemporaryDirectory</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;selenium_driverless_&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">name</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span> <span class="o">=</span> <span class="n">max_ws_size</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_auth</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">options</span><span class="p">:</span>
            <span class="n">options</span> <span class="o">=</span> <span class="n">ChromeOptions</span><span class="p">()</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">options</span><span class="o">.</span><span class="n">binary_location</span><span class="p">:</span>
            <span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">find_chrome_executable</span>
            <span class="n">options</span><span class="o">.</span><span class="n">binary_location</span> <span class="o">=</span> <span class="n">find_chrome_executable</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="p">:</span> <span class="n">ChromeOptions</span> <span class="o">=</span> <span class="n">options</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_has_incognito_contexts</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_started</span> <span class="o">=</span> <span class="kc">False</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="sa">f</span><span class="s1">&#39;&lt;</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="vm">__module__</span><span class="si">}</span><span class="s1">.</span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span><span class="si">}</span><span class="s1"> (session=&quot;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">id</span><span class="si">}</span><span class="s1">&quot;)&gt;&#39;</span>

    <span class="k">async</span> <span class="k">def</span> <span class="fm">__aenter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">start_session</span><span class="p">()</span>
        <span class="k">return</span> <span class="bp">self</span>

    <span class="k">def</span> <span class="fm">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span>

    <span class="k">async</span> <span class="k">def</span> <span class="fm">__aexit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_val</span><span class="p">,</span> <span class="n">exc_tb</span><span class="p">):</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">quit</span><span class="p">(</span><span class="n">clean_dirs</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">auto_clean_dirs</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_val</span><span class="p">,</span> <span class="n">exc_tb</span><span class="p">):</span>
        <span class="k">pass</span>

    <span class="k">def</span> <span class="fm">__await__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">start_session</span><span class="p">()</span><span class="o">.</span><span class="fm">__await__</span><span class="p">()</span>

    <span class="k">async</span> <span class="k">def</span> <span class="nf">start_session</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_started</span><span class="p">:</span>
            <span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">read</span>
            <span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">is_first_run</span><span class="p">,</span> <span class="n">get_default_ua</span><span class="p">,</span> <span class="n">set_default_ua</span>
            <span class="kn">from</span> <span class="nn">selenium_driverless.scripts.prefs</span> <span class="kn">import</span> <span class="n">read_prefs</span><span class="p">,</span> <span class="n">write_prefs</span>

            <span class="k">await</span> <span class="n">is_first_run</span><span class="p">()</span>
            <span class="n">user_agent</span> <span class="o">=</span> <span class="k">await</span> <span class="n">get_default_ua</span><span class="p">()</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">use_extension</span><span class="p">:</span>
                <span class="c1"># extension</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">add_extension</span><span class="p">(</span><span class="n">sel_driverless_path</span><span class="p">()</span> <span class="o">+</span> <span class="s2">&quot;files/mv3_extension&quot;</span><span class="p">)</span>

            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">debugger_address</span><span class="p">:</span>
                <span class="kn">from</span> <span class="nn">selenium_driverless.utils.utils</span> <span class="kn">import</span> <span class="n">random_port</span>
                <span class="n">port</span> <span class="o">=</span> <span class="n">random_port</span><span class="p">()</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">_debugger_address</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;127.0.0.1:</span><span class="si">{</span><span class="n">port</span><span class="si">}</span><span class="s2">&quot;</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;--remote-debugging-port=</span><span class="si">{</span><span class="n">port</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">headless</span> <span class="ow">and</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span><span class="p">:</span>
                <span class="c1"># patch useragent</span>
                <span class="k">if</span> <span class="n">user_agent</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;--user-agent=</span><span class="si">{</span><span class="n">user_agent</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;headless is detectable at first run&quot;</span><span class="p">)</span>

            <span class="c1"># handle prefs</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">user_data_dir</span><span class="p">:</span>
                <span class="n">prefs_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">user_data_dir</span> <span class="o">+</span> <span class="s2">&quot;/Default/Preferences&quot;</span>
                <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">prefs_path</span><span class="p">):</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_prefs</span> <span class="o">=</span> <span class="k">await</span> <span class="n">read_prefs</span><span class="p">(</span><span class="n">prefs_path</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">prefs_path</span><span class="p">),</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

                <span class="c1"># write prefs</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_prefs</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">prefs</span><span class="p">)</span>
                <span class="k">await</span> <span class="n">write_prefs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_prefs</span><span class="p">,</span> <span class="n">prefs_path</span><span class="p">)</span>
            <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">user_data_dir</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span>
                    <span class="s2">&quot;--user-data-dir=&quot;</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">_temp_dir</span> <span class="o">+</span> <span class="s2">&quot;/data_dir&quot;</span><span class="p">)</span>
                <span class="n">prefs_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">user_data_dir</span> <span class="o">+</span> <span class="s2">&quot;/Default/Preferences&quot;</span>
                <span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">prefs_path</span><span class="p">),</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

                <span class="c1"># write prefs</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_prefs</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">prefs</span><span class="p">)</span>
                <span class="k">await</span> <span class="n">write_prefs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_prefs</span><span class="p">,</span> <span class="n">prefs_path</span><span class="p">)</span>

            <span class="c1"># noinspection PyProtectedMember</span>
            <span class="c1"># handle extensions</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">_extension_paths</span><span class="p">:</span>
                <span class="kn">import</span> <span class="nn">zipfile</span>
                <span class="n">extension_paths</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_running_loop</span><span class="p">()</span>

                <span class="c1"># noinspection PyProtectedMember</span>
                <span class="k">def</span> <span class="nf">extractall</span><span class="p">():</span>
                    <span class="k">for</span> <span class="n">_path</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">_extension_paths</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">_path</span><span class="p">):</span>
                            <span class="k">with</span> <span class="n">zipfile</span><span class="o">.</span><span class="n">ZipFile</span><span class="p">(</span><span class="n">_path</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">zip_ref</span><span class="p">:</span>
                                <span class="n">_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_temp_dir</span> <span class="o">+</span> <span class="sa">f</span><span class="s2">&quot;/</span><span class="si">{</span><span class="n">uuid</span><span class="o">.</span><span class="n">uuid4</span><span class="p">()</span><span class="o">.</span><span class="n">hex</span><span class="si">}</span><span class="s2">&quot;</span>
                                <span class="n">zip_ref</span><span class="o">.</span><span class="n">extractall</span><span class="p">(</span><span class="n">_path</span><span class="p">)</span>
                        <span class="n">extension_paths</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">_path</span><span class="p">)</span>

                <span class="k">await</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_in_executor</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="n">extractall</span><span class="p">)</span>

                <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">arguments</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;--load-extension=&quot;</span> <span class="o">+</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">extension_paths</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">_extension_paths</span> <span class="o">=</span> <span class="p">[]</span>

            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">startup_url</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">startup_url</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">_startup_url</span> <span class="o">=</span> <span class="kc">None</span>

            <span class="n">options</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span>

            <span class="c1"># noinspection PyProtectedMember</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">_is_remote</span>

            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span><span class="p">:</span>
                <span class="n">path</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">binary_location</span>
                <span class="n">args</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">arguments</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_debug</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_stderr</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">stderr</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_stderr</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">TemporaryFile</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;selenium_driverless&quot;</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_stderr_file</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_stderr</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_process</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">(</span>
                    <span class="p">[</span><span class="n">path</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">],</span>
                    <span class="n">stdin</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span>
                    <span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span>
                    <span class="n">stderr</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_stderr</span><span class="p">,</span>
                    <span class="n">close_fds</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                    <span class="n">preexec_fn</span><span class="o">=</span><span class="n">os</span><span class="o">.</span><span class="n">setsid</span> <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s1">&#39;posix&#39;</span> <span class="k">else</span> <span class="kc">None</span><span class="p">,</span>
                    <span class="n">creationflags</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">CREATE_NEW_PROCESS_GROUP</span> <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s1">&#39;nt&#39;</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span>
                    <span class="n">shell</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                    <span class="n">text</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                    <span class="n">env</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">env</span>
                <span class="p">)</span>

                <span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">debugger_address</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)</span>
                <span class="n">port</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">port</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">port</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                    <span class="n">path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">user_data_dir</span> <span class="o">+</span> <span class="s2">&quot;/DevToolsActivePort&quot;</span>
                    <span class="k">while</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
                        <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.1</span><span class="p">)</span>
                    <span class="n">port</span> <span class="o">=</span> <span class="k">await</span> <span class="n">read</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">sel_root</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                    <span class="n">port</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">port</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">debugger_address</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;127.0.0.1:</span><span class="si">{</span><span class="n">port</span><span class="si">}</span><span class="s2">&quot;</span>

            <span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">debugger_address</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">port</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">port</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_host</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">host</span><span class="si">}</span><span class="s2">:</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">port</span><span class="si">}</span><span class="s2">&quot;</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_base_target</span> <span class="o">=</span> <span class="k">await</span> <span class="n">SyncBaseTarget</span><span class="p">(</span><span class="n">host</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="n">is_remote</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span><span class="p">,</span>
                                                         <span class="n">timeout</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span>
                                                         <span class="n">max_ws_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_base_target</span> <span class="o">=</span> <span class="k">await</span> <span class="n">BaseTarget</span><span class="p">(</span><span class="n">host</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="n">is_remote</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span><span class="p">,</span>
                                                     <span class="n">timeout</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span>
                                                     <span class="n">max_ws_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span><span class="p">)</span>

            <span class="c1"># fetch useragent at first headless run</span>
            <span class="c1"># noinspection PyUnboundLocalVariable</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span><span class="p">:</span>
                <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_base_target</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Browser.getVersion&quot;</span><span class="p">)</span>
                <span class="n">user_agent</span> <span class="o">=</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;userAgent&quot;</span><span class="p">]</span>
                <span class="n">user_agent</span> <span class="o">=</span> <span class="n">user_agent</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;HeadlessChrome&quot;</span><span class="p">,</span> <span class="s2">&quot;Chrome&quot;</span><span class="p">)</span>
                <span class="k">await</span> <span class="n">set_default_ua</span><span class="p">(</span><span class="n">user_agent</span><span class="p">)</span>

            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span><span class="p">:</span>
                <span class="c1"># noinspection PyUnboundLocalVariable</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">browser_pid</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process</span><span class="o">.</span><span class="n">pid</span>
            <span class="n">targets</span> <span class="o">=</span> <span class="k">await</span> <span class="n">get_json</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">target</span> <span class="ow">in</span> <span class="n">targets</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">target</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;page&quot;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">target</span><span class="p">[</span><span class="s2">&quot;url&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;chrome-extension://&quot;</span><span class="p">):</span>
                    <span class="n">target_id</span> <span class="o">=</span> <span class="n">target</span><span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">]</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_current_target</span> <span class="o">=</span> <span class="k">await</span> <span class="n">get_target</span><span class="p">(</span><span class="n">target_id</span><span class="o">=</span><span class="n">target_id</span><span class="p">,</span> <span class="n">host</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span>
                                                            <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span> <span class="n">is_remote</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span>
                                                            <span class="n">max_ws_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span><span class="p">,</span> <span class="n">driver</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>

                    <span class="c1"># handle the context</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">:</span>
                        <span class="n">context</span> <span class="o">=</span> <span class="k">await</span> <span class="n">SyncContext</span><span class="p">(</span><span class="n">base_target</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_current_target</span><span class="p">,</span> <span class="n">driver</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span>
                                                    <span class="n">max_ws_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">context</span> <span class="o">=</span> <span class="k">await</span> <span class="n">Context</span><span class="p">(</span><span class="n">base_target</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_current_target</span><span class="p">,</span> <span class="n">driver</span><span class="o">=</span><span class="bp">self</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span>
                                                <span class="n">max_ws_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span><span class="p">)</span>
                    <span class="n">_id</span> <span class="o">=</span> <span class="n">context</span><span class="o">.</span><span class="n">context_id</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_current_target</span><span class="o">.</span><span class="n">_context</span> <span class="o">=</span> <span class="n">context</span>

                    <span class="k">def</span> <span class="nf">remove_context</span><span class="p">():</span>
                        <span class="k">if</span> <span class="n">_id</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span><span class="p">:</span>
                            <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span><span class="p">[</span><span class="n">_id</span><span class="p">]</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_base_context</span> <span class="o">=</span> <span class="kc">None</span>

                    <span class="c1"># noinspection PyProtectedMember</span>
                    <span class="n">context</span><span class="o">.</span><span class="n">_closed_callbacks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">remove_context</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_current_context</span> <span class="o">=</span> <span class="n">context</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_base_context</span> <span class="o">=</span> <span class="n">context</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span><span class="p">[</span><span class="n">_id</span><span class="p">]</span> <span class="o">=</span> <span class="n">context</span>
                    <span class="k">break</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Emulation.setFocusEmulationEnabled&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;enabled&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">})</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">single_proxy</span><span class="p">:</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">set_single_proxy</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">single_proxy</span><span class="p">)</span>
            <span class="n">downloads_dir</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">downloads_dir</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">downloads_dir</span><span class="p">:</span>
                <span class="c1"># ensure download events are dispatched</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">set_download_behaviour</span><span class="p">(</span><span class="s2">&quot;allowAndName&quot;</span><span class="p">,</span> <span class="n">downloads_dir</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">set_download_behaviour</span><span class="p">(</span><span class="s2">&quot;default&quot;</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_started</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="k">return</span> <span class="bp">self</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">frame_tree</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        **async**</span>
<span class="sd">        all nested frames within the current target</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_context</span><span class="o">.</span><span class="n">frame_tree</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">targets</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">TargetInfo</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        **async**</span>
<span class="sd">        all targets within the current context</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_context</span><span class="o">.</span><span class="n">targets</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">contexts</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Context</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        **async**</span>
<span class="sd">        all (incognito) contexts on Chrome.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">targets</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_targets</span><span class="p">(</span><span class="n">context_id</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
        <span class="n">contexts</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">info</span> <span class="ow">in</span> <span class="n">targets</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
            <span class="n">_id</span> <span class="o">=</span> <span class="n">info</span><span class="o">.</span><span class="n">browser_context_id</span>
            <span class="k">if</span> <span class="n">_id</span><span class="p">:</span>
                <span class="n">context</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">_id</span><span class="p">)</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">context</span><span class="p">:</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">:</span>
                        <span class="n">context</span> <span class="o">=</span> <span class="k">await</span> <span class="n">SyncContext</span><span class="p">(</span><span class="n">base_target</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_current_target</span><span class="p">,</span> <span class="n">context_id</span><span class="o">=</span><span class="n">_id</span><span class="p">,</span>
                                                    <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span> <span class="n">max_ws_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span><span class="p">,</span> <span class="n">driver</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">context</span> <span class="o">=</span> <span class="k">await</span> <span class="n">Context</span><span class="p">(</span><span class="n">base_target</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_current_target</span><span class="p">,</span> <span class="n">context_id</span><span class="o">=</span><span class="n">_id</span><span class="p">,</span>
                                                <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span> <span class="n">max_ws_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span><span class="p">,</span> <span class="n">driver</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span>
                <span class="n">contexts</span><span class="p">[</span><span class="n">_id</span><span class="p">]</span> <span class="o">=</span> <span class="n">context</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">contexts</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span>

<div class="viewcode-block" id="Chrome.new_context"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.new_context">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">new_context</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">proxy_bypass_list</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">proxy_server</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span>
                          <span class="n">universal_access_origins</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">url</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="s2">&quot;about:blank&quot;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Context</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        creates a new (incognito) context</span>

<span class="sd">        :param url: the url the first tab will start at. &quot;about:blank&quot; by default</span>
<span class="sd">        :param universal_access_origins: An optional list of origins to grant unlimited cross-origin access to. Parts of the URL other than those constituting origin are ignored</span>

<span class="sd">        .. warning::</span>
<span class="sd">            The proxy parameter doesn&#39;t work on Windows due to `crbug#1310057 &lt;https://bugs.chromium.org/p/chromium/issues/detail?id=1310057&gt;`__.</span>

<span class="sd">        .. code block:: python</span>
<span class="sd">            await driver.set_auth(&quot;username&quot;, &quot;password&quot;, &quot;localhost:5000&quot;)</span>
<span class="sd">            context = await driver.new_context(proxy_bypass_list=[&quot;localhost&quot;], proxy_server=&quot;http://localhost:5000&quot;)</span>

<span class="sd">        :param proxy_server: a proxy-server to use for the context</span>
<span class="sd">        :param proxy_bypass_list: a list of proxies to ignore</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">ensure_extensions_incognito_allowed</span><span class="p">()</span>
        <span class="k">if</span> <span class="n">proxy_bypass_list</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">proxy_bypass_list</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;localhost&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">proxy_server</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">proxy_server</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
        <span class="n">args</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;disposeOnDetach&quot;</span><span class="p">:</span> <span class="kc">False</span><span class="p">}</span>
        <span class="k">if</span> <span class="n">proxy_bypass_list</span><span class="p">:</span>
            <span class="n">args</span><span class="p">[</span><span class="s2">&quot;proxyBypassList&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">proxy_bypass_list</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">proxy_server</span> <span class="ow">is</span> <span class="kc">True</span><span class="p">):</span>
            <span class="n">args</span><span class="p">[</span><span class="s2">&quot;proxyServer&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">proxy_server</span>
        <span class="k">if</span> <span class="n">universal_access_origins</span><span class="p">:</span>
            <span class="n">args</span><span class="p">[</span><span class="s2">&quot;originsWithUniversalNetworkAccess&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">universal_access_origins</span>

        <span class="c1"># create context ensuring extension racing conditions</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_auth_interception_enabled</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="n">has_incognito_ctxs</span> <span class="o">=</span> <span class="ow">not</span> <span class="p">(</span><span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_has_incognito_contexts</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_has_incognito_contexts</span> <span class="o">=</span> <span class="kc">True</span>
        <span class="n">mv3_ext</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">mv3_extension</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_mv3_extension</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">res</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_target</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Target.createBrowserContext&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_mv3_extension</span> <span class="o">=</span> <span class="n">mv3_ext</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_auth_interception_enabled</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_has_incognito_contexts</span> <span class="o">=</span> <span class="n">has_incognito_ctxs</span>
            <span class="k">raise</span> <span class="n">e</span>

        <span class="n">_id</span> <span class="o">=</span> <span class="n">res</span><span class="p">[</span><span class="s2">&quot;browserContextId&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">:</span>
            <span class="n">context</span> <span class="o">=</span> <span class="k">await</span> <span class="n">SyncContext</span><span class="p">(</span><span class="n">base_target</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_base_target</span><span class="p">,</span> <span class="n">context_id</span><span class="o">=</span><span class="n">_id</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span>
                                        <span class="n">is_incognito</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                        <span class="n">max_ws_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span><span class="p">,</span> <span class="n">driver</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">context</span> <span class="o">=</span> <span class="k">await</span> <span class="n">Context</span><span class="p">(</span><span class="n">base_target</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_base_target</span><span class="p">,</span> <span class="n">context_id</span><span class="o">=</span><span class="n">_id</span><span class="p">,</span> <span class="n">loop</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_loop</span><span class="p">,</span>
                                    <span class="n">is_incognito</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">max_ws_size</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">_max_ws_size</span><span class="p">,</span>
                                    <span class="n">driver</span><span class="o">=</span><span class="bp">self</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span><span class="p">[</span><span class="n">_id</span><span class="p">]</span> <span class="o">=</span> <span class="n">context</span>

        <span class="k">def</span> <span class="nf">remove_context</span><span class="p">():</span>
            <span class="k">if</span> <span class="n">_id</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span><span class="p">:</span>
                <span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span><span class="p">[</span><span class="n">_id</span><span class="p">]</span>

        <span class="c1"># noinspection PyProtectedMember</span>
        <span class="n">context</span><span class="o">.</span><span class="n">_closed_callbacks</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">remove_context</span><span class="p">)</span>
        <span class="k">await</span> <span class="n">context</span><span class="o">.</span><span class="n">switch_to</span><span class="o">.</span><span class="n">new_window</span><span class="p">(</span><span class="s2">&quot;window&quot;</span><span class="p">,</span> <span class="n">activate</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">url</span><span class="o">=</span><span class="n">url</span><span class="p">)</span>
        <span class="n">tabs</span> <span class="o">=</span> <span class="k">await</span> <span class="n">context</span><span class="o">.</span><span class="n">get_targets</span><span class="p">(</span><span class="n">_type</span><span class="o">=</span><span class="s2">&quot;page&quot;</span><span class="p">,</span> <span class="n">context_id</span><span class="o">=</span><span class="n">_id</span><span class="p">)</span>
        <span class="n">context</span><span class="o">.</span><span class="n">_current_target</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">tabs</span><span class="o">.</span><span class="n">values</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">Target</span>
        <span class="n">context</span><span class="o">.</span><span class="n">_current_target</span><span class="o">.</span><span class="n">_timeout</span> <span class="o">=</span> <span class="mi">5</span>

        <span class="c1"># reload auth &amp; extension target to fix non-applied auth</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_auth</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_mv3_extension</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
                <span class="c1"># ensure racing conditions with extension</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">mv3_target</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">mv3_extension</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_auth_interception_enabled</span> <span class="o">=</span> <span class="kc">False</span>
                    <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_auth_interception</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">set_flag</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                    <span class="k">await</span> <span class="n">mv3_target</span><span class="o">.</span><span class="n">execute_script</span><span class="p">(</span><span class="s2">&quot;globalThis.authCreds = arguments[0]&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_auth</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span>
                                                    <span class="n">unique_context</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                <span class="k">except</span> <span class="p">(</span><span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">,</span> <span class="ne">TimeoutError</span><span class="p">):</span>
                    <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.1</span><span class="p">)</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_mv3_extension</span> <span class="o">=</span> <span class="kc">None</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_auth_interception_enabled</span> <span class="o">=</span> <span class="kc">True</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_mv3_extension</span> <span class="o">=</span> <span class="n">mv3_target</span>
                    <span class="k">return</span> <span class="n">context</span>
        <span class="k">return</span> <span class="n">context</span></div>

<div class="viewcode-block" id="Chrome.get_targets"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_targets">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_targets</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
                          <span class="n">_type</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;page&quot;</span><span class="p">,</span> <span class="s2">&quot;background_page&quot;</span><span class="p">,</span> <span class="s2">&quot;service_worker&quot;</span><span class="p">,</span> <span class="s2">&quot;browser&quot;</span><span class="p">,</span> <span class="s2">&quot;other&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                          <span class="n">context_id</span><span class="p">:</span> <span class="nb">str</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="s2">&quot;self&quot;</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">TargetInfo</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        get all targets within the current context</span>
<span class="sd">        :param _type: filter by target type</span>
<span class="sd">        :param context_id: if ``None``, this function returns all targets for all contexts.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_context</span><span class="o">.</span><span class="n">get_targets</span><span class="p">(</span><span class="n">_type</span><span class="o">=</span><span class="n">_type</span><span class="p">,</span> <span class="n">context_id</span><span class="o">=</span><span class="n">context_id</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">current_target</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Target</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        the current Target</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_context</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_context</span><span class="o">.</span><span class="n">current_target</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_current_target</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">base_target</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">BaseTarget</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        The connection handle for the global connection to Chrome</span>

<span class="sd">        .. warning::</span>
<span class="sd">            only the bindings for using the CDP-protocol on BaseTarget supported</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_base_target</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">mv3_extension</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">10</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Target</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        **async** the target for the background script of the by default loaded Chrome-extension (manifest-version==3)</span>

<span class="sd">        .. note:</span>
<span class="sd">            for incognito context, the extension uses the &quot;spanning&quot; configuration, as there isn&#39;t a way to debug &quot;split&quot; mode over CDP</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_has_incognito_contexts</span><span class="p">:</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">ensure_extensions_incognito_allowed</span><span class="p">()</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mv3_extension</span><span class="p">:</span>
            <span class="kn">import</span> <span class="nn">re</span>
            <span class="kn">import</span> <span class="nn">time</span>
            <span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
            <span class="n">extension_target</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">while</span> <span class="ow">not</span> <span class="n">extension_target</span><span class="p">:</span>
                <span class="n">targets</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_targets</span><span class="p">(</span><span class="n">context_id</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">target</span> <span class="ow">in</span> <span class="n">targets</span><span class="o">.</span><span class="n">values</span><span class="p">():</span>
                    <span class="k">if</span> <span class="n">target</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;service_worker&quot;</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">fullmatch</span><span class="p">(</span>
                                <span class="sa">r</span><span class="s2">&quot;chrome-extension://(.*)/&quot;</span>
                                <span class="sa">r</span><span class="s2">&quot;driverless_background_mv3_243ffdd55e32a012b4f253b2879af978\.js&quot;</span><span class="p">,</span>
                                <span class="n">target</span><span class="o">.</span><span class="n">url</span><span class="p">):</span>
                            <span class="n">extension_target</span> <span class="o">=</span> <span class="n">target</span><span class="o">.</span><span class="n">Target</span>
                            <span class="k">break</span>
                <span class="k">if</span> <span class="ow">not</span> <span class="n">extension_target</span><span class="p">:</span>
                    <span class="k">if</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">timeout</span><span class="p">:</span>
                        <span class="k">raise</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Couldn&#39;t find mv3 extension within </span><span class="si">{</span><span class="n">timeout</span><span class="si">}</span><span class="s2"> seconds&quot;</span><span class="p">)</span>
            <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="c1"># fix WebRTC leak</span>
                    <span class="k">await</span> <span class="n">extension_target</span><span class="o">.</span><span class="n">execute_script</span><span class="p">(</span>
                        <span class="s2">&quot;chrome.privacy.network.webRTCIPHandlingPolicy.set(arguments[0])&quot;</span><span class="p">,</span>
                        <span class="p">{</span><span class="s2">&quot;value&quot;</span><span class="p">:</span> <span class="s2">&quot;disable_non_proxied_udp&quot;</span><span class="p">},</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">unique_context</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                <span class="k">except</span> <span class="p">(</span><span class="n">asyncio</span><span class="o">.</span><span class="n">TimeoutError</span><span class="p">,</span> <span class="ne">TimeoutError</span><span class="p">):</span>
                    <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.2</span><span class="p">)</span>
                    <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">mv3_extension</span>
                <span class="k">except</span> <span class="n">JSEvalException</span><span class="p">:</span>
                    <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.2</span><span class="p">)</span>
                <span class="k">except</span> <span class="n">cdp_socket</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">CDPError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">code</span> <span class="o">==</span> <span class="o">-</span><span class="mi">32000</span> <span class="ow">and</span> <span class="n">e</span><span class="o">.</span><span class="n">message</span> <span class="o">==</span> <span class="s1">&#39;Could not find object with given id&#39;</span><span class="p">:</span>
                        <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.2</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">break</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_mv3_extension</span> <span class="o">=</span> <span class="n">extension_target</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mv3_extension</span>

<div class="viewcode-block" id="Chrome.ensure_extensions_incognito_allowed"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.ensure_extensions_incognito_allowed">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">ensure_extensions_incognito_allowed</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        ensure that all installed Chrome-extensions are allowed in incognito context.</span>

<span class="sd">        .. warning::</span>
<span class="sd">            Generally, the extension decides whether to use the ``split``, ``spanning`` or ``not_allowed`` configuration.</span>
<span class="sd">            For changing this behaviour, you&#39;ll have to modify the ``manifest.json`` file within the compressed extension or directory.</span>
<span class="sd">            See `developer.chrome.com/docs/extensions/reference/manifest/incognito &lt;https://developer.chrome.com/docs/extensions/reference/manifest/incognito?hl=en&gt;`__.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_extensions_incognito_allowed</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_extensions_incognito_allowed</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="c1"># noinspection PyTypeChecker</span>
            <span class="n">page</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">base_ctx</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_base_context</span>
                <span class="n">page</span><span class="p">:</span> <span class="n">Context</span> <span class="o">=</span> <span class="k">await</span> <span class="n">base_ctx</span><span class="o">.</span><span class="n">new_window</span><span class="p">(</span><span class="s2">&quot;tab&quot;</span><span class="p">,</span> <span class="s2">&quot;chrome://extensions&quot;</span><span class="p">,</span> <span class="n">activate</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
                <span class="n">script</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">                    async function make_global(){</span>
<span class="s2">                        const extensions = await chrome.developerPrivate.getExtensionsInfo();</span>
<span class="s2">                        extensions.forEach( async function(extension)  {</span>
<span class="s2">                            chrome.developerPrivate.updateExtensionConfiguration({</span>
<span class="s2">                                extensionId: extension.id,</span>
<span class="s2">                                incognitoAccess: true</span>
<span class="s2">                            })</span>
<span class="s2">                        });</span>
<span class="s2">                    };</span>
<span class="s2">                    await make_global()</span>
<span class="s2">                &quot;&quot;&quot;</span>
                <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.1</span><span class="p">)</span>
                <span class="k">await</span> <span class="n">page</span><span class="o">.</span><span class="n">eval_async</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">unique_context</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                <span class="n">EXC_HANDLER</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_extensions_incognito_allowed</span> <span class="o">=</span> <span class="kc">False</span>
                <span class="k">if</span> <span class="n">page</span><span class="p">:</span>
                    <span class="k">await</span> <span class="n">page</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">ensure_extensions_incognito_allowed</span><span class="p">()</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_extensions_incognito_allowed</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">await</span> <span class="n">page</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">base_context</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Context</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        the Context which isn&#39;t incognito</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_base_context</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">downloads_dir</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;the current downloads directory for the current context&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_target</span><span class="o">.</span><span class="n">downloads_dir_for_context</span><span class="p">(</span><span class="n">context_id</span><span class="o">=</span><span class="s2">&quot;DEFAULT&quot;</span><span class="p">)</span>

<div class="viewcode-block" id="Chrome.set_download_behaviour"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.set_download_behaviour">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_download_behaviour</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">behaviour</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;deny&quot;</span><span class="p">,</span> <span class="s2">&quot;allow&quot;</span><span class="p">,</span> <span class="s2">&quot;allowAndName&quot;</span><span class="p">,</span> <span class="s2">&quot;default&quot;</span><span class="p">],</span>
                                     <span class="n">path</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;set the download behaviour</span>

<span class="sd">        :param behaviour: the behaviour to set the downloading to</span>
<span class="sd">        :param path: the path to the default download directory</span>

<span class="sd">        .. warning::</span>
<span class="sd">            setting ``behaviour=allow`` instead of ``allowAndName`` can cause some bugs</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_context</span><span class="o">.</span><span class="n">set_download_behaviour</span><span class="p">(</span><span class="n">behaviour</span><span class="p">,</span> <span class="n">path</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">current_context</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Context</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        the current context switched to</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_current_context</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span><span class="p">:</span>
                <span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_contexts</span><span class="o">.</span><span class="n">values</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_current_context</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">_isolated_context_id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="c1"># noinspection PyProtectedMember</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_context</span><span class="o">.</span><span class="n">_isolated_context_id</span>

<div class="viewcode-block" id="Chrome.get_target"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_target">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_target</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target_id</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Target</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        get a Target by TargetId for advanced usage of the CDP protocol</span>
<span class="sd">        :param target_id:</span>
<span class="sd">        :param timeout: timeout in seconds for connecting to the target if it&#39;s not tracked already</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">target_id</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_context</span><span class="o">.</span><span class="n">get_target</span><span class="p">(</span><span class="n">target_id</span><span class="o">=</span><span class="n">target_id</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.get_target_for_iframe"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_target_for_iframe">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_target_for_iframe</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iframe</span><span class="p">:</span> <span class="n">WebElement</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Target</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        get the Target for a specific iframe</span>

<span class="sd">        .. warning::</span>
<span class="sd">            only cross-iframes have a Target due to `OOPIF &lt;https://www.chromium.org/developers/design-documents/oop-iframes/&gt;`__. See `site-isolation &lt;https://www.chromium.org/Home/chromium-security/site-isolation/&gt;`__</span>
<span class="sd">            For a general solution, have a look at ``WebElement.content_document`` instead</span>

<span class="sd">        :param iframe: the iframe to get the Target for</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">get_target_for_iframe</span><span class="p">(</span><span class="n">iframe</span><span class="o">=</span><span class="n">iframe</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.get_targets_for_iframes"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_targets_for_iframes">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_targets_for_iframes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iframes</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">WebElement</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">Target</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        returns a list of targets for iframes</span>
<span class="sd">        see ``webdriver.Chrome.get_target_for_iframe`` for more information</span>

<span class="sd">        :param iframes: the iframe to get the targets for</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">get_targets_for_iframes</span><span class="p">(</span><span class="n">iframes</span><span class="o">=</span><span class="n">iframes</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.wait_download"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.wait_download">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">wait_download</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="mi">30</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        wait for a download on the current tab</span>

<span class="sd">        returns something like</span>

<span class="sd">        .. code-block:: python</span>

<span class="sd">            {</span>
<span class="sd">                &quot;frameId&quot;: &quot;2D543B5E8B14945B280C537A4882A695&quot;,</span>
<span class="sd">                &quot;guid&quot;: &quot;c91df4d5-9b45-4962-84df-3749bd3f926d&quot;,</span>
<span class="sd">                &quot;url&quot;: &quot;https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf&quot;,</span>
<span class="sd">                &quot;suggestedFilename&quot;: &quot;dummy.pdf&quot;,</span>

<span class="sd">                # only if options.downloads_dir specified</span>
<span class="sd">                &quot;guid_file&quot;: &quot;D:\\System\\AppData\\PyCharm\\scratches\\downloads\\c91df4d5-9b45-4962-84df-3749bd3f926d&quot;</span>
<span class="sd">            }</span>

<span class="sd">        :param timeout: time in seconds to wait for a download</span>

<span class="sd">        .. warning::</span>
<span class="sd">            downloads from iframes not supported yet</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">wait_download</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.get"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">referrer</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">wait_load</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">30</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">Union</span><span class="p">[</span>
        <span class="kc">None</span><span class="p">,</span> <span class="nb">dict</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Loads a web page in the current Target</span>

<span class="sd">        :param url: the url to load.</span>
<span class="sd">        :param referrer: the referrer to load the page with</span>
<span class="sd">        :param wait_load: whether to wait for the webpage to load</span>
<span class="sd">        :param timeout: the maximum time in seconds for waiting on load</span>

<span class="sd">        returns the same as :func:`Target.wait_download &lt;selenium_driverless.types.target.Target.wait_download&gt;` if the url initiates a download</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="o">=</span><span class="n">url</span><span class="p">,</span> <span class="n">referrer</span><span class="o">=</span><span class="n">referrer</span><span class="p">,</span> <span class="n">wait_load</span><span class="o">=</span><span class="n">wait_load</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">title</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;**async** the title of the current target&quot;&quot;&quot;</span>
        <span class="n">target</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target_info</span>
        <span class="k">return</span> <span class="n">target</span><span class="o">.</span><span class="n">title</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">current_pointer</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Pointer</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;the :class:`Pointer &lt;selenium_driverless.input.pointer.Pointer&gt;` for this target&quot;&quot;&quot;</span>
        <span class="n">target</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span>
        <span class="k">return</span> <span class="n">target</span><span class="o">.</span><span class="n">pointer</span>

<div class="viewcode-block" id="Chrome.send_keys"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.send_keys">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">send_keys</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">text</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        send text &amp; keys to the current target</span>

<span class="sd">        :param text: the text to send</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">send_keys</span><span class="p">(</span><span class="n">text</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.execute_raw_script"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.execute_raw_script">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">execute_raw_script</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">script</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">await_res</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">False</span><span class="p">,</span>
                                 <span class="n">serialization</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;deep&quot;</span><span class="p">,</span> <span class="s2">&quot;json&quot;</span><span class="p">,</span> <span class="s2">&quot;idOnly&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;deep&quot;</span><span class="p">,</span>
                                 <span class="n">max_depth</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">execution_context_id</span><span class="p">,</span>
                                 <span class="n">unique_context</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;executes a JavaScript on ``GlobalThis`` such as</span>

<span class="sd">        .. code-block:: js</span>

<span class="sd">            function(...arguments){return document}</span>

<span class="sd">        :param script: the script as a string</span>
<span class="sd">        :param args: the argument which are passed to the function. Those can be either json-serializable or a RemoteObject such as WebElement</span>
<span class="sd">        :param await_res: whether to await the function or the return value of it</span>
<span class="sd">        :param serialization: can be one of ``deep``, ``json``, ``idOnly``</span>
<span class="sd">        :param max_depth: The maximum depth objects get serialized.</span>
<span class="sd">        :param timeout: the maximum time to wait for the execution to complete</span>
<span class="sd">        :param execution_context_id: the execution context id to run the JavaScript in. Exclusive with unique_context</span>
<span class="sd">        :param unique_context: whether to use an isolated context to run the Script in.</span>

<span class="sd">        see `Runtime.callFunctionOn &lt;https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-callFunctionOn&gt;`_</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">execute_raw_script</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">await_res</span><span class="o">=</span><span class="n">await_res</span><span class="p">,</span>
                                                            <span class="n">serialization</span><span class="o">=</span><span class="n">serialization</span><span class="p">,</span> <span class="n">max_depth</span><span class="o">=</span><span class="n">max_depth</span><span class="p">,</span>
                                                            <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span> <span class="n">execution_context_id</span><span class="o">=</span><span class="n">execution_context_id</span><span class="p">,</span>
                                                            <span class="n">unique_context</span><span class="o">=</span><span class="n">unique_context</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.execute_script"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.execute_script">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">execute_script</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">script</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">max_depth</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">serialization</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                             <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">execution_context_id</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                             <span class="n">unique_context</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;executes JavaScript synchronously on ``GlobalThis`` such as</span>

<span class="sd">        .. code-block:: js</span>

<span class="sd">            return document</span>

<span class="sd">        see :func:`Target.execute_raw_script &lt;selenium_driverless.types.target.Target.execute_raw_script&gt;` for argument descriptions</span>
<span class="sd">                &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">execute_script</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">max_depth</span><span class="o">=</span><span class="n">max_depth</span><span class="p">,</span> <span class="n">serialization</span><span class="o">=</span><span class="n">serialization</span><span class="p">,</span>
                                                        <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span> <span class="n">execution_context_id</span><span class="o">=</span><span class="n">execution_context_id</span><span class="p">,</span>
                                                        <span class="n">unique_context</span><span class="o">=</span><span class="n">unique_context</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.execute_async_script"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.execute_async_script">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">execute_async_script</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">script</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">max_depth</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span>
                                   <span class="n">serialization</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">execution_context_id</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                                   <span class="n">unique_context</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;executes JavaScript asynchronously on ``GlobalThis`` such as</span>

<span class="sd">        .. warning::</span>
<span class="sd">            using execute_async_script is not recommended as it doesn&#39;t handle exceptions correctly.</span>
<span class="sd">            Use :func:`Chrome.eval_async &lt;selenium_driverless.webdriver.Chrome.eval_async&gt;`</span>

<span class="sd">        .. code-block:: js</span>

<span class="sd">            resolve = arguments[arguments.length-1]</span>

<span class="sd">        see :func:`Target.execute_raw_script &lt;selenium_driverless.types.target.Target.execute_raw_script&gt;` for argument descriptions</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">execute_async_script</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">max_depth</span><span class="o">=</span><span class="n">max_depth</span><span class="p">,</span>
                                                              <span class="n">serialization</span><span class="o">=</span><span class="n">serialization</span><span class="p">,</span>
                                                              <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span>
                                                              <span class="n">execution_context_id</span><span class="o">=</span><span class="n">execution_context_id</span><span class="p">,</span>
                                                              <span class="n">unique_context</span><span class="o">=</span><span class="n">unique_context</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.eval_async"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.eval_async">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">eval_async</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">script</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">max_depth</span><span class="p">:</span> <span class="nb">int</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span>
                         <span class="n">serialization</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">,</span> <span class="n">execution_context_id</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                         <span class="n">unique_context</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;executes JavaScript asynchronously on ``GlobalThis`` such as</span>

<span class="sd">        .. code-block:: js</span>

<span class="sd">            res = await fetch(&quot;https://httpbin.org/get&quot;);</span>
<span class="sd">            // mind CORS!</span>
<span class="sd">            json = await res.json()</span>
<span class="sd">            return json</span>

<span class="sd">        see :func:`Target.execute_raw_script &lt;selenium_driverless.types.target.Target.execute_raw_script&gt;` for argument descriptions</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">eval_async</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="n">max_depth</span><span class="o">=</span><span class="n">max_depth</span><span class="p">,</span> <span class="n">serialization</span><span class="o">=</span><span class="n">serialization</span><span class="p">,</span>
                                                    <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span>
                                                    <span class="n">execution_context_id</span><span class="o">=</span><span class="n">execution_context_id</span><span class="p">,</span>
                                                    <span class="n">unique_context</span><span class="o">=</span><span class="n">unique_context</span><span class="p">)</span></div>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">current_url</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;**async** current URL of the current Target</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">target</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span>
        <span class="k">return</span> <span class="k">await</span> <span class="n">target</span><span class="o">.</span><span class="n">url</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">page_source</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;**async** html of the current page.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">target</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span>
        <span class="k">return</span> <span class="k">await</span> <span class="n">target</span><span class="o">.</span><span class="n">page_source</span>

<div class="viewcode-block" id="Chrome.close"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.close">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">2</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Closes the current target (only works for tabs).</span>
<span class="sd">        :param timeout: timeout in seconds for the tab to close</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.focus"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.focus">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">focus</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;focuses the current target (only works for tabs)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">focus</span><span class="p">()</span></div>

<div class="viewcode-block" id="Chrome.quit"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.quit">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">quit</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">30</span><span class="p">,</span> <span class="n">clean_dirs</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Closes Chrome</span>
<span class="sd">        :param timeout: the maximum time waiting for chrome to quit correctly</span>
<span class="sd">        :param clean_dirs: whether to clean out the user-data-dir directory</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">selenium_driverless</span> <span class="kn">import</span> <span class="n">EXC_HANDLER</span>

        <span class="n">loop</span> <span class="o">=</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">get_running_loop</span><span class="p">()</span>

        <span class="k">def</span> <span class="nf">clean_dirs_sync</span><span class="p">(</span><span class="n">dirs</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="nb">str</span><span class="p">]):</span>
            <span class="k">for</span> <span class="n">_dir</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span>
                <span class="k">while</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">_dir</span><span class="p">):</span>
                    <span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">_dir</span><span class="p">,</span> <span class="n">ignore_errors</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_started</span><span class="p">:</span>
            <span class="n">start</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span>
            <span class="c1"># noinspection PyUnresolvedReferences</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="c1"># assumption: chrome is still running</span>
                <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_target</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Browser.close&quot;</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span>
            <span class="k">except</span> <span class="n">websockets</span><span class="o">.</span><span class="n">ConnectionClosedError</span><span class="p">:</span>
                <span class="k">pass</span>
            <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                <span class="n">EXC_HANDLER</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_remote</span><span class="p">:</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                    <span class="c1"># assumption: chrome is being shutdown manually or programmatically</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="k">await</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_in_executor</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process</span><span class="o">.</span><span class="n">wait</span><span class="p">(</span><span class="n">timeout</span><span class="p">))</span>
                    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                        <span class="n">EXC_HANDLER</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">_process</span> <span class="o">=</span> <span class="kc">None</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="c1"># assumption: chrome hasn&#39;t closed within timeout, killing with force</span>
                    <span class="c1"># wait for process to be killed</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                        <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s1">&#39;posix&#39;</span><span class="p">:</span>
                            <span class="n">os</span><span class="o">.</span><span class="n">killpg</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getpgid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_process</span><span class="o">.</span><span class="n">pid</span><span class="p">),</span> <span class="n">signal</span><span class="o">.</span><span class="n">SIGTERM</span><span class="p">)</span>
                        <span class="k">else</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">_process</span><span class="o">.</span><span class="n">terminate</span><span class="p">()</span>
                        <span class="k">try</span><span class="p">:</span>
                            <span class="k">await</span> <span class="n">loop</span><span class="o">.</span><span class="n">run_in_executor</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="k">lambda</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_process</span><span class="o">.</span><span class="n">wait</span><span class="p">(</span><span class="n">timeout</span><span class="p">))</span>
                        <span class="k">except</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">TimeoutExpired</span><span class="p">:</span>
                            <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">name</span> <span class="o">==</span> <span class="s1">&#39;posix&#39;</span><span class="p">:</span>
                                <span class="n">os</span><span class="o">.</span><span class="n">killpg</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">getpgid</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_process</span><span class="o">.</span><span class="n">pid</span><span class="p">),</span> <span class="n">signal</span><span class="o">.</span><span class="n">SIGKILL</span><span class="p">)</span>
                            <span class="k">else</span><span class="p">:</span>
                                <span class="bp">self</span><span class="o">.</span><span class="n">_process</span><span class="o">.</span><span class="n">kill</span><span class="p">()</span>
                <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                    <span class="n">EXC_HANDLER</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
                <span class="k">finally</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_started</span> <span class="o">=</span> <span class="kc">False</span>
                    <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_stderr_file</span><span class="p">:</span>
                        <span class="k">try</span><span class="p">:</span>
                            <span class="bp">self</span><span class="o">.</span><span class="n">_stderr</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
                        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                            <span class="n">EXC_HANDLER</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>

                    <span class="c1"># clean temp dir for extensions etc</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">wait_for</span><span class="p">(</span>
                            <span class="c1"># wait for</span>
                            <span class="n">loop</span><span class="o">.</span><span class="n">run_in_executor</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span>
                                                 <span class="k">lambda</span><span class="p">:</span> <span class="n">clean_dirs_sync</span><span class="p">(</span>
                                                     <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_temp_dir</span><span class="p">])),</span>
                            <span class="n">timeout</span><span class="o">=</span><span class="nb">max</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">timeout</span> <span class="o">-</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span><span class="p">))))</span>
                    <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                        <span class="n">EXC_HANDLER</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>

                    <span class="k">if</span> <span class="n">clean_dirs</span><span class="p">:</span>
                        <span class="c1"># clean user-data-dir for chrome</span>
                        <span class="k">try</span><span class="p">:</span>
                            <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">wait_for</span><span class="p">(</span>
                                <span class="c1"># wait for</span>
                                <span class="n">loop</span><span class="o">.</span><span class="n">run_in_executor</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span>
                                                     <span class="k">lambda</span><span class="p">:</span> <span class="n">clean_dirs_sync</span><span class="p">(</span>
                                                         <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">_options</span><span class="o">.</span><span class="n">user_data_dir</span><span class="p">])),</span>
                                <span class="n">timeout</span><span class="o">=</span><span class="nb">max</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">timeout</span> <span class="o">-</span> <span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">perf_counter</span><span class="p">()</span> <span class="o">-</span> <span class="n">start</span><span class="p">))))</span>
                        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                                <span class="s2">&quot;driver hasn&#39;t quit correctly, &quot;</span>
                                <span class="s2">&quot;files might be left in your temp folder &amp; chrome might still be running&quot;</span><span class="p">,</span>
                                <span class="ne">ResourceWarning</span><span class="p">)</span>
                            <span class="k">raise</span> <span class="n">e</span></div>

    <span class="k">def</span> <span class="fm">__del__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_started</span><span class="p">:</span>
                <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
                    <span class="s2">&quot;driver hasn&#39;t quit correctly, &quot;</span>
                    <span class="s2">&quot;files might be left in your temp folder &amp; chrome might still be running&quot;</span><span class="p">,</span>
                    <span class="ne">ResourceWarning</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="k">pass</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">current_target_info</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">TargetInfo</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;**async** TargetInfo of the current target&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">info</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">current_window_handle</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;current TargetId</span>

<span class="sd">        .. warning::</span>

<span class="sd">            this is deprecated and will be removed</span>
<span class="sd">            use ``webdriver.Chrome.current_target.id`` instead</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;&quot;webdriver.Chrome.current_window_handle&quot; is deprecated and will be removed</span><span class="se">\n</span><span class="s1">&#39;</span>
                      <span class="s1">&#39;use &quot;webdriver.Chrome.current_target.id&quot; instead&#39;</span><span class="p">,</span> <span class="ne">DeprecationWarning</span><span class="p">)</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">id</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">current_window_id</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;**async** the ``WindowId`` of the window the current Target belongs to</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">result</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Browser.getWindowForTarget&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;targetId&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">id</span><span class="p">})</span>
        <span class="k">return</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;windowId&quot;</span><span class="p">]</span>

    <span class="nd">@property</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">window_handles</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="n">TargetInfo</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;**async** TargetInfo on all tabs in the current context</span>

<span class="sd">        .. warning::</span>

<span class="sd">            the tabs aren&#39;t ordered by position in the window. Do not rely on the index, but iterate and filter them.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span>
            <span class="s2">&quot;the tabs aren&#39;t ordered by position in the window. Do not rely on the index, but iterate and filter them.&quot;</span><span class="p">)</span>
        <span class="n">tabs</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">targets</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">targets</span>
        <span class="k">for</span> <span class="n">info</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">targets</span><span class="o">.</span><span class="n">values</span><span class="p">()):</span>
            <span class="k">if</span> <span class="n">info</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="s2">&quot;page&quot;</span><span class="p">:</span>
                <span class="n">tabs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">info</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">tabs</span>

<div class="viewcode-block" id="Chrome.new_window"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.new_window">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">new_window</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">type_hint</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;tab&quot;</span><span class="p">,</span> <span class="s2">&quot;window&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;tab&quot;</span><span class="p">,</span> <span class="n">url</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
                         <span class="n">activate</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Target</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Creates a new window or tab in the current context</span>

<span class="sd">        :param type_hint: whether to create a tab or window</span>
<span class="sd">        :param url: the url which the new window should start on. Defaults to about:blank</span>
<span class="sd">        :param activate: whether to explicitly activate/focus the window</span>

<span class="sd">        .. code-block:: python</span>

<span class="sd">            new_target = driver.new_window(&#39;tab&#39;)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_context</span><span class="o">.</span><span class="n">new_window</span><span class="p">(</span><span class="n">type_hint</span><span class="o">=</span><span class="n">type_hint</span><span class="p">,</span> <span class="n">url</span><span class="o">=</span><span class="n">url</span><span class="p">,</span> <span class="n">activate</span><span class="o">=</span><span class="n">activate</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.set_window_state"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.set_window_state">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_window_state</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">state</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;normal&quot;</span><span class="p">,</span> <span class="s2">&quot;minimized&quot;</span><span class="p">,</span> <span class="s2">&quot;maximized&quot;</span><span class="p">,</span> <span class="s2">&quot;fullscreen&quot;</span><span class="p">]):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;sets the window state on the window the current Target belongs to</span>
<span class="sd">        :param state: the state to set</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">window_id</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_window_id</span>
        <span class="n">bounds</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;windowState&quot;</span><span class="p">:</span> <span class="n">state</span><span class="p">}</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Browser.setWindowBounds&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;bounds&quot;</span><span class="p">:</span> <span class="n">bounds</span><span class="p">,</span> <span class="s2">&quot;windowId&quot;</span><span class="p">:</span> <span class="n">window_id</span><span class="p">})</span></div>

<div class="viewcode-block" id="Chrome.normalize_window"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.normalize_window">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">normalize_window</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Normalizes the window position and size on the window the current Target belongs to</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">set_window_state</span><span class="p">(</span><span class="s2">&quot;normal&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.maximize_window"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.maximize_window">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">maximize_window</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Maximizes the window the current Target belongs to&quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">set_window_state</span><span class="p">(</span><span class="s2">&quot;maximized&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.fullscreen_window"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.fullscreen_window">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">fullscreen_window</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;enters fullscreen on the window the current Target belongs to&quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">set_window_state</span><span class="p">(</span><span class="s2">&quot;fullscreen&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.minimize_window"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.minimize_window">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">minimize_window</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;minimizes the window the current Target belongs to.</span>

<span class="sd">        .. warning::</span>

<span class="sd">            Minimizing isn&#39;t recommended as it can throttle some functionalities in chrome.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">set_window_state</span><span class="p">(</span><span class="s2">&quot;minimized&quot;</span><span class="p">)</span></div>

    <span class="c1"># noinspection PyUnusedLocal</span>
<div class="viewcode-block" id="Chrome.print_page"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.print_page">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">print_page</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Prints the page (current target =&gt; tab) to PDF</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">target</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span>
        <span class="k">return</span> <span class="k">await</span> <span class="n">target</span><span class="o">.</span><span class="n">print_page</span><span class="p">()</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">switch_to</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">SwitchTo</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;SwitchTo handle</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_context</span><span class="o">.</span><span class="n">switch_to</span>

    <span class="c1"># Navigation</span>
<div class="viewcode-block" id="Chrome.back"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.back">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">back</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Goes one step backward in the browser history on the current target (has to be a tab).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">back</span><span class="p">()</span></div>

<div class="viewcode-block" id="Chrome.forward"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.forward">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">forward</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Goes one step forward in the browser history on the current target (has to be a tab).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">forward</span><span class="p">()</span></div>

<div class="viewcode-block" id="Chrome.refresh"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.refresh">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">refresh</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Refreshes the current tab (target).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">refresh</span><span class="p">()</span></div>

    <span class="c1"># Options</span>
<div class="viewcode-block" id="Chrome.get_cookies"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_cookies">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_cookies</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">List</span><span class="p">[</span><span class="nb">dict</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;list of cookies for the current tab</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">get_cookies</span><span class="p">()</span></div>

<div class="viewcode-block" id="Chrome.get_cookie"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_cookie">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_cookie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">Optional</span><span class="p">[</span><span class="n">typing</span><span class="o">.</span><span class="n">Dict</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Get a single cookie by name. Returns the cookie if found, None if</span>
<span class="sd">        not.</span>

<span class="sd">        :param name: name of the cookie</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">get_cookie</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.delete_cookie"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.delete_cookie">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">delete_cookie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">url</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">domain</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                            <span class="n">path</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Deletes a single cookie with the given name in the current tab.</span>

<span class="sd">        :param name: name of the cookie to delete</span>
<span class="sd">        :param url: url of the cookie</span>
<span class="sd">        :param domain: domain of the cookie</span>
<span class="sd">        :param path: path of the cookie</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">delete_cookie</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">url</span><span class="o">=</span><span class="n">url</span><span class="p">,</span> <span class="n">domain</span><span class="o">=</span><span class="n">domain</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="n">path</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.delete_all_cookies"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.delete_all_cookies">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">delete_all_cookies</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Delete all cookies in the current (incognito-) context.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">delete_all_cookies</span><span class="p">()</span></div>

    <span class="c1"># noinspection GrazieInspection</span>
<div class="viewcode-block" id="Chrome.add_cookie"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.add_cookie">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">add_cookie</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cookie_dict</span><span class="p">:</span> <span class="nb">dict</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Adds a cookie in the current (incognito-) context</span>

<span class="sd">        :param cookie_dict: see `Network.CookieParam &lt;https://chromedevtools.github.io/devtools-protocol/tot/Network/#type-CookieParam&gt;`__</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">add_cookie</span><span class="p">(</span><span class="n">cookie_dict</span><span class="o">=</span><span class="n">cookie_dict</span><span class="p">)</span></div>

    <span class="c1"># Timeouts</span>
<div class="viewcode-block" id="Chrome.sleep"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.sleep">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">async</span> <span class="k">def</span> <span class="nf">sleep</span><span class="p">(</span><span class="n">time_to_wait</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="c1"># noinspection GrazieInspection</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;sleep</span>
<span class="sd">                .. note::</span>
<span class="sd">                    use this one instead of time.sleep in the sync version.</span>

<span class="sd">                :param time_to_wait: time in seconds to sleep</span>
<span class="sd">                &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="n">asyncio</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">time_to_wait</span><span class="p">)</span></div>

    <span class="c1"># noinspection PyUnusedLocal</span>
<div class="viewcode-block" id="Chrome.find_element"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.find_element">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">find_element</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">by</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">WebElement</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;find an element in the current target</span>

<span class="sd">        :param by: one of the locators at :func:`By &lt;selenium_driverless.types.by.By&gt;`</span>
<span class="sd">        :param value: the actual query to find the element by</span>
<span class="sd">        :param timeout: how long to wait for the element to exist</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">find_element</span><span class="p">(</span><span class="n">by</span><span class="o">=</span><span class="n">by</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">value</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.find_elements"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.find_elements">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">find_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">by</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mi">3</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">WebElement</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;find multiple elements in the current target</span>

<span class="sd">        :param by: one of the locators at :func:`By &lt;selenium_driverless.types.by.By&gt;`</span>
<span class="sd">        :param value: the actual query to find the elements by</span>
<span class="sd">        :param timeout: how long to wait for not being in a page reload loop in seconds</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">find_elements</span><span class="p">(</span><span class="n">by</span><span class="o">=</span><span class="n">by</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="n">value</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.search_elements"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.search_elements">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">search_elements</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">query</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">List</span><span class="p">[</span><span class="n">WebElement</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        find elements similarly to how &quot;CTRL+F&quot; in the DevTools Console works</span>

<span class="sd">        :param query: Plain text to find elements with</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">search_elements</span><span class="p">(</span><span class="n">query</span><span class="o">=</span><span class="n">query</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.get_screenshot_as_file"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_screenshot_as_file">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_screenshot_as_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Saves a screenshot of the current tab to a PNG image file.</span>
<span class="sd">        :param filename: The path you wish to save your screenshot to. should end with a `.png` extension.</span>

<span class="sd">        .. code-block:: python</span>

<span class="sd">            driver.get_screenshot_as_file(&#39;screenshots/test.png&#39;)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">get_screenshot_as_file</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">filename</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.save_screenshot"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.save_screenshot">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">save_screenshot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;alias to :func: `driver.get_screenshot_as_file &lt;selenium_driverless.webdriver.Chrome.get_screenshot_as_file&gt;`&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_screenshot_as_file</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.get_screenshot_as_png"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_screenshot_as_png">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_screenshot_as_png</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bytes</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Gets the screenshot of the current tab as a binary data.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">get_screenshot_as_png</span><span class="p">()</span></div>

<div class="viewcode-block" id="Chrome.snapshot"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.snapshot">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">snapshot</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;gets the current snapshot as mhtml&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">snapshot</span><span class="p">()</span></div>

<div class="viewcode-block" id="Chrome.save_snapshot"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.save_snapshot">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">save_snapshot</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">:</span> <span class="nb">str</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Saves a snapshot of the current window to a MHTML file.</span>

<span class="sd">        :param filename: The full path you wish to save your snapshot to. This</span>
<span class="sd">                   should end with a ``.mhtml`` extension.</span>

<span class="sd">        .. code-block:: Python</span>

<span class="sd">            await driver.get_snapshot(&#39;snapshot.mhtml&#39;)</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">save_snapshot</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span></div>

    <span class="c1"># noinspection PyPep8Naming</span>
<div class="viewcode-block" id="Chrome.set_window_size"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.set_window_size">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_window_size</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">width</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">height</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Sets the width and height of the window, the current tab is within (unless ``windowHandle`` specified)</span>

<span class="sd">        :param width: the width in pixels to set the window to</span>
<span class="sd">        :param height: the height in pixels to set the window to</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">set_window_rect</span><span class="p">(</span><span class="n">width</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">width</span><span class="p">),</span> <span class="n">height</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">height</span><span class="p">))</span></div>

    <span class="c1"># noinspection PyPep8Naming</span>
<div class="viewcode-block" id="Chrome.get_window_size"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_window_size">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_window_size</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Gets the width and height of the current window.</span>

<span class="sd">        returns something like:</span>
<span class="sd">        .. code-block: json</span>

<span class="sd">            {&quot;width&quot;:1280, &quot;height&quot;:720}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">size</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_window_rect</span><span class="p">()</span>

        <span class="k">if</span> <span class="n">size</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;value&quot;</span><span class="p">):</span>
            <span class="n">size</span> <span class="o">=</span> <span class="n">size</span><span class="p">[</span><span class="s2">&quot;value&quot;</span><span class="p">]</span>

        <span class="k">return</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">size</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;width&quot;</span><span class="p">,</span> <span class="s2">&quot;height&quot;</span><span class="p">)}</span></div>

    <span class="c1"># noinspection PyPep8Naming</span>
<div class="viewcode-block" id="Chrome.set_window_position"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.set_window_position">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_window_position</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="nb">int</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Sets the x,y position of the window, the current tab is in.</span>

<span class="sd">        :param x: the x-coordinate in pixels to set the window position</span>
<span class="sd">        :param y: the y-coordinate in pixels to set the window position</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">set_window_rect</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">y</span><span class="o">=</span><span class="nb">int</span><span class="p">(</span><span class="n">y</span><span class="p">))</span></div>

    <span class="c1"># noinspection PyPep8Naming</span>
<div class="viewcode-block" id="Chrome.get_window_position"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_window_position">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_window_position</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Gets the x,y position of the window, the current tab is in.</span>

<span class="sd">        returns something like:</span>
<span class="sd">        .. code-block: json</span>

<span class="sd">            {&quot;x&quot;:0, &quot;y&quot;:0}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">position</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_window_rect</span><span class="p">()</span>

        <span class="k">return</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">position</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">,</span> <span class="s2">&quot;y&quot;</span><span class="p">)}</span></div>

<div class="viewcode-block" id="Chrome.get_window_rect"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_window_rect">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_window_rect</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Gets the x, y, with and height coordinates of the window, the current tab is in.</span>

<span class="sd">        returns something like:</span>
<span class="sd">        .. code-block: json</span>

<span class="sd">            {&quot;x&quot;:0, &quot;y&quot;:0,</span>
<span class="sd">            &quot;width&quot;:1280, &quot;height&quot;:720,</span>
<span class="sd">            &quot;windowState&quot;:&quot;normal&quot;</span>
<span class="sd">            }</span>

<span class="sd">        .. note::</span>

<span class="sd">            ``windowState`` can be one of &quot;normal&quot;, &quot;minimized&quot;, &quot;maximized&quot;, &quot;fullscreen&quot;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">json</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Browser.getWindowBounds&quot;</span><span class="p">,</span> <span class="p">{</span><span class="s2">&quot;windowId&quot;</span><span class="p">:</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_window_id</span><span class="p">})</span>
        <span class="n">json</span> <span class="o">=</span> <span class="n">json</span><span class="p">[</span><span class="s2">&quot;bounds&quot;</span><span class="p">]</span>
        <span class="n">json</span><span class="p">[</span><span class="s2">&quot;x&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">json</span><span class="p">[</span><span class="s2">&quot;left&quot;</span><span class="p">]</span>
        <span class="k">del</span> <span class="n">json</span><span class="p">[</span><span class="s2">&quot;left&quot;</span><span class="p">]</span>
        <span class="n">json</span><span class="p">[</span><span class="s2">&quot;y&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">json</span><span class="p">[</span><span class="s2">&quot;top&quot;</span><span class="p">]</span>
        <span class="k">del</span> <span class="n">json</span><span class="p">[</span><span class="s2">&quot;top&quot;</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">json</span></div>

<div class="viewcode-block" id="Chrome.set_window_rect"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.set_window_rect">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_window_rect</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Sets the x, y, width and height coordinates of the window the current target is in.</span>

<span class="sd">        :param x: the x-coordinate in pixels to set the window position</span>
<span class="sd">        :param y: the y-coordinate in pixels to set the window position</span>
<span class="sd">        :param width: the width in pixels to set the window to</span>
<span class="sd">        :param height: the height in pixels to set the window to</span>

<span class="sd">        .. note::</span>

<span class="sd">            either x and y or with and height have to be specified</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="p">(</span><span class="n">x</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">y</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">height</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">width</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;x and y or height and width need values&quot;</span><span class="p">)</span>

        <span class="n">bounds</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;left&quot;</span><span class="p">:</span> <span class="n">x</span><span class="p">,</span> <span class="s2">&quot;top&quot;</span><span class="p">:</span> <span class="n">y</span><span class="p">,</span> <span class="s2">&quot;width&quot;</span><span class="p">:</span> <span class="n">width</span><span class="p">,</span> <span class="s1">&#39;height&#39;</span><span class="p">:</span> <span class="n">height</span><span class="p">}</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Browser.setWindowBounds&quot;</span><span class="p">,</span>
                                   <span class="p">{</span><span class="s2">&quot;windowId&quot;</span><span class="p">:</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_window_id</span><span class="p">,</span> <span class="s2">&quot;bounds&quot;</span><span class="p">:</span> <span class="n">bounds</span><span class="p">})</span>
        <span class="n">bounds</span><span class="p">[</span><span class="s2">&quot;x&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">bounds</span><span class="p">[</span><span class="s2">&quot;left&quot;</span><span class="p">]</span>
        <span class="k">del</span> <span class="n">bounds</span><span class="p">[</span><span class="s2">&quot;left&quot;</span><span class="p">]</span>
        <span class="n">bounds</span><span class="p">[</span><span class="s2">&quot;y&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">bounds</span><span class="p">[</span><span class="s2">&quot;top&quot;</span><span class="p">]</span>
        <span class="k">del</span> <span class="n">bounds</span><span class="p">[</span><span class="s2">&quot;top&quot;</span><span class="p">]</span>

        <span class="k">return</span> <span class="n">bounds</span></div>

<div class="viewcode-block" id="Chrome.get_network_conditions"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_network_conditions">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_network_conditions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Gets Chromium network emulation settings.</span>

<span class="sd">        returns a dict like:</span>

<span class="sd">        .. code-block:: python</span>

<span class="sd">            {&quot;latency&quot;: 4, &quot;download_throughput&quot;: 2, &quot;upload_throughput&quot;: 2,</span>
<span class="sd">            &quot;offline&quot;: False}</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">get_network_conditions</span><span class="p">()</span></div>

    <span class="c1"># noinspection SpellCheckingInspection</span>
<div class="viewcode-block" id="Chrome.set_network_conditions"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.set_network_conditions">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_network_conditions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">offline</span><span class="p">:</span> <span class="nb">bool</span><span class="p">,</span> <span class="n">latency</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span> <span class="n">download_throughput</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
                                     <span class="n">upload_throughput</span><span class="p">:</span> <span class="nb">int</span><span class="p">,</span>
                                     <span class="n">connection_type</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span>
                                         <span class="s2">&quot;none&quot;</span><span class="p">,</span> <span class="s2">&quot;cellular2g&quot;</span><span class="p">,</span> <span class="s2">&quot;cellular3g&quot;</span><span class="p">,</span> <span class="s2">&quot;cellular4g&quot;</span><span class="p">,</span> <span class="s2">&quot;bluetooth&quot;</span><span class="p">,</span> <span class="s2">&quot;ethernet&quot;</span><span class="p">,</span> <span class="s2">&quot;wifi&quot;</span><span class="p">,</span> <span class="s2">&quot;wimax&quot;</span><span class="p">,</span> <span class="s2">&quot;other&quot;</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
        <span class="c1"># noinspection GrazieInspection</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Sets Chromium network emulation settings.</span>

<span class="sd">        :param offline:</span>
<span class="sd">        :param latency:  additional latency in ms</span>
<span class="sd">        :param download_throughput: maximum throughput, 500 * 1024 for example</span>
<span class="sd">        :param upload_throughput: maximum throughput, 500 * 1024 for example</span>
<span class="sd">        :param connection_type: the connection type</span>

<span class="sd">        .. note::</span>

<span class="sd">            &#39;throughput&#39; can be used to set both (for download and upload).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">set_network_conditions</span><span class="p">(</span><span class="n">offline</span><span class="o">=</span><span class="n">offline</span><span class="p">,</span> <span class="n">latency</span><span class="o">=</span><span class="n">latency</span><span class="p">,</span>
                                                                <span class="n">download_throughput</span><span class="o">=</span><span class="n">download_throughput</span><span class="p">,</span>
                                                                <span class="n">upload_throughput</span><span class="o">=</span><span class="n">upload_throughput</span><span class="p">,</span>
                                                                <span class="n">connection_type</span><span class="o">=</span><span class="n">connection_type</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.delete_network_conditions"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.delete_network_conditions">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">delete_network_conditions</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Resets Chromium network emulation settings.&quot;&quot;&quot;</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">delete_network_conditions</span><span class="p">()</span></div>

<div class="viewcode-block" id="Chrome.set_permissions"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.set_permissions">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_permissions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">value</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Literal</span><span class="p">[</span><span class="s2">&quot;granted&quot;</span><span class="p">,</span> <span class="s2">&quot;denied&quot;</span><span class="p">,</span> <span class="s2">&quot;prompt&quot;</span><span class="p">],</span>
                              <span class="n">origin</span><span class="p">:</span> <span class="nb">str</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Sets Applicable Permission</span>

<span class="sd">        :param name: The item to set the permission on.</span>
<span class="sd">        :param value: The value to set on the item</span>
<span class="sd">        :param origin: the origin the permission for. Applies to any origin if not set</span>

<span class="sd">        .. code-block:: python</span>

<span class="sd">            target.set_permissions(&#39;clipboard-read&#39;, &#39;denied&#39;)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">settings</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;granted&quot;</span><span class="p">,</span> <span class="s2">&quot;denied&quot;</span><span class="p">,</span> <span class="s2">&quot;prompt&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">value</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;value needs to be within </span><span class="si">{</span><span class="n">settings</span><span class="si">}</span><span class="s2">, but got </span><span class="si">{</span><span class="n">value</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
        <span class="n">args</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;permission&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="n">name</span><span class="p">},</span> <span class="s2">&quot;setting&quot;</span><span class="p">:</span> <span class="n">value</span><span class="p">}</span>
        <span class="k">if</span> <span class="n">origin</span><span class="p">:</span>
            <span class="n">args</span><span class="p">[</span><span class="s2">&quot;origin&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">origin</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="s2">&quot;Browser.setPermission&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.set_proxy"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.set_proxy">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_proxy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">proxy_config</span><span class="p">):</span>
        <span class="c1"># noinspection GrazieInspection</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot; set a proxy dynamically</span>

<span class="sd">        Example parameters:</span>

<span class="sd">        .. code-block:: python</span>

<span class="sd">            proxy_config = {</span>
<span class="sd">                &quot;mode&quot;: &quot;fixed_servers&quot;,</span>
<span class="sd">                &quot;rules&quot;: {</span>
<span class="sd">                    &quot;proxyForHttp&quot;: {</span>
<span class="sd">                        &quot;scheme&quot;: scheme,</span>
<span class="sd">                        &quot;host&quot;: host,</span>
<span class="sd">                        &quot;port&quot;: port</span>
<span class="sd">                    },</span>
<span class="sd">                    &quot;proxyForHttps&quot;: {</span>
<span class="sd">                        &quot;scheme&quot;: scheme,</span>
<span class="sd">                        &quot;host&quot;: host,</span>
<span class="sd">                        &quot;port&quot;: port</span>
<span class="sd">                    },</span>
<span class="sd">                    &quot;proxyForFtp&quot;: {</span>
<span class="sd">                        &quot;scheme&quot;: scheme,</span>
<span class="sd">                        &quot;host&quot;: host,</span>
<span class="sd">                        &quot;port&quot;: port</span>
<span class="sd">                    },</span>
<span class="sd">                    &quot;fallbackProxy&quot;: {</span>
<span class="sd">                        &quot;scheme&quot;: scheme,</span>
<span class="sd">                        &quot;host&quot;: host,</span>
<span class="sd">                        &quot;port&quot;: port</span>
<span class="sd">                    },</span>
<span class="sd">                    &quot;bypassList&quot;: [&quot;&lt;local&gt;&quot;]</span>
<span class="sd">                }</span>
<span class="sd">            }</span>

<span class="sd">        :param proxy_config: see `developer.chrome.com/docs/extensions/reference/proxy &lt;https://developer.chrome.com/docs/extensions/reference/proxy/&gt;`__ for reference</span>

<span class="sd">        for authentification, see :func:`webdriver.Chrome.set_auth &lt;selenium_driverless.webdriver.Chrome.set_auth&gt;`</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">extension</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">mv3_extension</span>
        <span class="k">await</span> <span class="n">extension</span><span class="o">.</span><span class="n">eval_async</span><span class="p">(</span><span class="s2">&quot;await chrome.proxy.settings.set(arguments[0])&quot;</span><span class="p">,</span>
                                   <span class="p">{</span><span class="s2">&quot;value&quot;</span><span class="p">:</span> <span class="n">proxy_config</span><span class="p">,</span> <span class="s2">&quot;scope&quot;</span><span class="p">:</span> <span class="s1">&#39;regular&#39;</span><span class="p">},</span> <span class="n">unique_context</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.set_single_proxy"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.set_single_proxy">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_single_proxy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">proxy</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">bypass_list</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set a single proxy dynamically to be applied in all contexts.</span>

<span class="sd">        .. code-block:: python</span>

<span class="sd">            &quot;http://user1:passwrd1@example.proxy.com:5001/&quot;</span>

<span class="sd">        .. warning::</span>

<span class="sd">            - Only supported when Chrome has been started with driverless or the extension at ``selenium_driverless/files/mv3_extension`` has been loaded into the browser.</span>

<span class="sd">            - ``Socks5`` doesn&#39;t support authentication due to `crbug#1309413 &lt;https://bugs.chromium.org/p/chromium/issues/detail?id=1309413&gt;`__.</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="c1"># parse scheme</span>
        <span class="n">proxy</span> <span class="o">=</span> <span class="n">proxy</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;://&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">proxy</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">scheme</span><span class="p">,</span> <span class="n">proxy</span> <span class="o">=</span> <span class="n">proxy</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">scheme</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="n">proxy</span> <span class="o">=</span> <span class="n">proxy</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">proxy</span> <span class="o">=</span> <span class="n">proxy</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;@&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">proxy</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">creds</span><span class="p">,</span> <span class="n">proxy</span> <span class="o">=</span> <span class="n">proxy</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">proxy</span> <span class="o">=</span> <span class="n">proxy</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">creds</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="c1"># parse host &amp; port</span>
        <span class="n">proxy</span> <span class="o">=</span> <span class="n">proxy</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">proxy</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">host</span><span class="p">,</span> <span class="n">port</span> <span class="o">=</span> <span class="n">proxy</span>
            <span class="n">port</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">port</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">port</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="n">host</span> <span class="o">=</span> <span class="n">proxy</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">rule</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;host&quot;</span><span class="p">:</span> <span class="n">host</span><span class="p">}</span>
        <span class="k">if</span> <span class="n">scheme</span><span class="p">:</span>
            <span class="n">rule</span><span class="p">[</span><span class="s2">&quot;scheme&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">scheme</span>
        <span class="k">if</span> <span class="n">port</span><span class="p">:</span>
            <span class="n">rule</span><span class="p">[</span><span class="s2">&quot;port&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">port</span>
        <span class="k">if</span> <span class="n">bypass_list</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">bypass_list</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;&lt;local&gt;&quot;</span><span class="p">]</span>
        <span class="n">proxy_config</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;mode&quot;</span><span class="p">:</span> <span class="s2">&quot;fixed_servers&quot;</span><span class="p">,</span>
            <span class="s2">&quot;rules&quot;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s2">&quot;proxyForHttp&quot;</span><span class="p">:</span> <span class="n">rule</span><span class="p">,</span>
                <span class="s2">&quot;proxyForHttps&quot;</span><span class="p">:</span> <span class="n">rule</span><span class="p">,</span>
                <span class="s2">&quot;proxyForFtp&quot;</span><span class="p">:</span> <span class="n">rule</span><span class="p">,</span>
                <span class="s2">&quot;fallbackProxy&quot;</span><span class="p">:</span> <span class="n">rule</span><span class="p">,</span>
                <span class="s2">&quot;bypassList&quot;</span><span class="p">:</span> <span class="n">bypass_list</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">set_proxy</span><span class="p">(</span><span class="n">proxy_config</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">creds</span><span class="p">:</span>
            <span class="n">user</span><span class="p">,</span> <span class="n">passw</span> <span class="o">=</span> <span class="n">creds</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)</span>
            <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">set_auth</span><span class="p">(</span><span class="n">user</span><span class="p">,</span> <span class="n">passw</span><span class="p">,</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">host</span><span class="si">}</span><span class="s2">:</span><span class="si">{</span><span class="n">port</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.clear_proxy"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.clear_proxy">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">clear_proxy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Clear the applied proxy (=&gt; use no proxy at all) in all contexts.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">extension</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">mv3_extension</span>
        <span class="k">await</span> <span class="n">extension</span><span class="o">.</span><span class="n">eval_async</span><span class="p">(</span><span class="s2">&quot;&quot;&quot;</span>
<span class="s2">            await chrome.proxy.settings.set(</span>
<span class="s2">              {value: {mode: &quot;direct&quot;}, scope: &#39;regular&#39;}</span>
<span class="s2">            );</span>
<span class="s2">        &quot;&quot;&quot;</span><span class="p">,</span> <span class="n">unique_context</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></div>

    <span class="k">async</span> <span class="k">def</span> <span class="nf">_ensure_auth_interception</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="o">=</span> <span class="mf">0.3</span><span class="p">,</span> <span class="n">set_flag</span><span class="p">:</span> <span class="nb">bool</span> <span class="o">=</span> <span class="kc">True</span><span class="p">):</span>
        <span class="c1"># internal, to re-apply auth interception which is broken when a new context gets opened. Due to how extensions in incognito work</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_auth_interception_enabled</span><span class="p">:</span>
            <span class="n">script</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
<span class="s2">                        if(globalThis.authCreds == undefined){globalThis.authCreds = </span><span class="si">{}</span><span class="s2">}</span>
<span class="s2">                        globalThis.onAuth = function onAuth(details) {</span>
<span class="s2">                            return globalThis.authCreds[details.challenger.host+&quot;:&quot;+details.challenger.port]</span>
<span class="s2">                        }</span>
<span class="s2">                        chrome.webRequest.onAuthRequired.addListener(</span>
<span class="s2">                            onAuth,</span>
<span class="s2">                            {urls: [&quot;&lt;all_urls&gt;&quot;]},</span>
<span class="s2">                            [&#39;blocking&#39;]</span>
<span class="s2">                            );</span>
<span class="s2">                        &quot;&quot;&quot;</span>
            <span class="n">mv3_target</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">mv3_extension</span>
            <span class="k">await</span> <span class="n">mv3_target</span><span class="o">.</span><span class="n">execute_script</span><span class="p">(</span><span class="n">script</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span> <span class="n">unique_context</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">set_flag</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_auth_interception_enabled</span> <span class="o">=</span> <span class="kc">True</span>

<div class="viewcode-block" id="Chrome.set_auth"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.set_auth">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_auth</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">username</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">password</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">host_with_port</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Set authentication dynamically to be applied in all contexts.</span>

<span class="sd">        .. code-block:: python</span>

<span class="sd">            driver.set_auth(&quot;user1&quot;,&quot;passwrd1&quot;, &quot;example.com:5001&quot;)</span>

<span class="sd">        .. warning::</span>

<span class="sd">            - Only supported when Chrome has been started with driverless or the extension at ``selenium_driverless/files/mv3_extension`` has been loaded into the browser.</span>

<span class="sd">            - ``Socks5`` doesn&#39;t support authentication due to `crbug#1309413 &lt;https://bugs.chromium.org/p/chromium/issues/detail?id=1309413&gt;`__.</span>

<span class="sd">        :param username:</span>
<span class="sd">        :param password:</span>
<span class="sd">        :param host_with_port: in format &quot;example.com:5001&quot;</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># provide auth</span>
        <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">_ensure_auth_interception</span><span class="p">()</span>
        <span class="n">mv3_target</span> <span class="o">=</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">mv3_extension</span>
        <span class="n">arg</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s2">&quot;authCredentials&quot;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s2">&quot;username&quot;</span><span class="p">:</span> <span class="n">username</span><span class="p">,</span>
                <span class="s2">&quot;password&quot;</span><span class="p">:</span> <span class="n">password</span>
            <span class="p">}</span>
        <span class="p">}</span>
        <span class="k">await</span> <span class="n">mv3_target</span><span class="o">.</span><span class="n">execute_script</span><span class="p">(</span><span class="s2">&quot;globalThis.authCreds[arguments[1]] = arguments[0]&quot;</span><span class="p">,</span> <span class="n">arg</span><span class="p">,</span> <span class="n">host_with_port</span><span class="p">,</span>
                                        <span class="n">unique_context</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_auth</span><span class="p">[</span><span class="n">host_with_port</span><span class="p">]</span> <span class="o">=</span> <span class="n">arg</span></div>

<div class="viewcode-block" id="Chrome.wait_for_cdp"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.wait_for_cdp">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">wait_for_cdp</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        wait for an event on the current target</span>
<span class="sd">        see :func:`Target.wait_for_cdp &lt;selenium_driverless.types.target.Target.wait_for_cdp&gt;` for reference</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">wait_for_cdp</span><span class="p">(</span><span class="n">event</span><span class="o">=</span><span class="n">event</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.add_cdp_listener"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.add_cdp_listener">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">add_cdp_listener</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">callback</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="nb">dict</span><span class="p">],</span> <span class="nb">any</span><span class="p">]):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        add a listener for a CDP event on the current target</span>
<span class="sd">        see :func:`Target.add_cdp_listener &lt;selenium_driverless.types.target.Target.add_cdp_listener&gt;` for reference</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">add_cdp_listener</span><span class="p">(</span><span class="n">event</span><span class="o">=</span><span class="n">event</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="n">callback</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.remove_cdp_listener"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.remove_cdp_listener">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">remove_cdp_listener</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">callback</span><span class="p">:</span> <span class="n">typing</span><span class="o">.</span><span class="n">Callable</span><span class="p">[[</span><span class="nb">dict</span><span class="p">],</span> <span class="nb">any</span><span class="p">]):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        remove a listener for a CDP event on the current target</span>
<span class="sd">        see :func:`Target.remove_cdp_listener &lt;selenium_driverless.types.target.Target.remove_cdp_listener&gt;` for reference</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">remove_cdp_listener</span><span class="p">(</span><span class="n">event</span><span class="o">=</span><span class="n">event</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="n">callback</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.get_cdp_event_iter"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_cdp_event_iter">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_cdp_event_iter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">typing</span><span class="o">.</span><span class="n">AsyncIterable</span><span class="p">[</span><span class="nb">dict</span><span class="p">]:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        iterate over CDP events on the current target</span>
<span class="sd">        see :func:`Target.get_cdp_event_iter &lt;selenium_driverless.types.target.Target.get_cdp_event_iter&gt;` for reference</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">get_cdp_event_iter</span><span class="p">(</span><span class="n">event</span><span class="o">=</span><span class="n">event</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.execute_cdp_cmd"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.execute_cdp_cmd">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">execute_cdp_cmd</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cmd</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="n">cmd_args</span><span class="p">:</span> <span class="nb">dict</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span>
                              <span class="n">timeout</span><span class="p">:</span> <span class="nb">float</span> <span class="ow">or</span> <span class="kc">None</span> <span class="o">=</span> <span class="mi">10</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Execute Chrome Devtools Protocol command on the current target</span>
<span class="sd">        executes it on :class:`Target.execute_cdp_cmd &lt;selenium_driverless.types.base_target.BaseTarget&gt;`</span>
<span class="sd">        if ``message:&#39;Not allowed&#39;`` received</span>
<span class="sd">        see :func:`Target.execute_cdp_cmd &lt;selenium_driverless.types.target.Target.execute_cdp_cmd&gt;` for reference</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_context</span><span class="o">.</span><span class="n">execute_cdp_cmd</span><span class="p">(</span><span class="n">cmd</span><span class="o">=</span><span class="n">cmd</span><span class="p">,</span> <span class="n">cmd_args</span><span class="o">=</span><span class="n">cmd_args</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.fetch"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.fetch">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">fetch</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        executes a JS ``fetch`` request within the current target</span>
<span class="sd">        see :func:`Target.fetch &lt;selenium_driverless.types.target.Target.fetch&gt;` for reference</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">fetch</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.xhr"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.xhr">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">xhr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        executes a JS ``XMLHttpRequest`` request within the current target</span>
<span class="sd">        see :func:`Target.fetch &lt;selenium_driverless.types.target.Target.fetch&gt;` for reference</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">xhr</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>

    <span class="c1"># noinspection PyTypeChecker</span>
<div class="viewcode-block" id="Chrome.get_sinks"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_sinks">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_sinks</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">list</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :Returns: A list of sinks available for Cast.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">get_sinks</span><span class="p">()</span></div>

<div class="viewcode-block" id="Chrome.get_issue_message"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.get_issue_message">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">get_issue_message</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        :Returns: An error message when there is any issue in a Cast session.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">get_issue_message</span><span class="p">()</span></div>

<div class="viewcode-block" id="Chrome.set_sink_to_use"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.set_sink_to_use">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">set_sink_to_use</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sink_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Sets a specific sink, using its name, as a Cast session receiver</span>
<span class="sd">        target.</span>

<span class="sd">        :param sink_name: Name of the sink to use as the target.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">set_sink_to_use</span><span class="p">(</span><span class="n">sink_name</span><span class="o">=</span><span class="n">sink_name</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.start_desktop_mirroring"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.start_desktop_mirroring">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">start_desktop_mirroring</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sink_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Starts a desktop mirroring session on a specific receiver target.</span>

<span class="sd">        :param sink_name: Name of the sink to use as the target.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">start_desktop_mirroring</span><span class="p">(</span><span class="n">sink_name</span><span class="o">=</span><span class="n">sink_name</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.start_tab_mirroring"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.start_tab_mirroring">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">start_tab_mirroring</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sink_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Starts a tab mirroring session on a specific receiver target.</span>

<span class="sd">        :param sink_name: Name of the sink to use as the target.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">start_tab_mirroring</span><span class="p">(</span><span class="n">sink_name</span><span class="o">=</span><span class="n">sink_name</span><span class="p">)</span></div>

<div class="viewcode-block" id="Chrome.stop_casting"><a class="viewcode-back" href="../../api/Chrome.html#selenium_driverless.webdriver.Chrome.stop_casting">[docs]</a>    <span class="k">async</span> <span class="k">def</span> <span class="nf">stop_casting</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sink_name</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span>
<span class="w">        </span><span class="sd">&quot;&quot;&quot;Stops the existing Cast session on a specific receiver target.</span>

<span class="sd">        :Args:</span>
<span class="sd">         - sink_name: Name of the sink to stop the Cast session.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="k">await</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_target</span><span class="o">.</span><span class="n">stop_casting</span><span class="p">(</span><span class="n">sink_name</span><span class="o">=</span><span class="n">sink_name</span><span class="p">)</span></div></div>
</pre></div>

           </div>
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 2024, Aurin Aegerter (aka Steve, kaliiiiiiiiii).</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>